<template>
  <div id="init">正在跳转，请稍后...
  </div>
</template>

<script>
export default {
  data () {
    return {
      userRoles: []
    }
  },
  methods: {
    inRoles (str) {
      let arr = this.userRoles
      // arr = 'aaabbROLE_admin'
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    checkLogin () {
      if (localStorage.getItem('Roles')) {
        this.userRoles = JSON.parse(localStorage.getItem('Roles'))
      }
      if (this.userRoles && this.userRoles.length > 0) {
        this.$http.post(`/account/userinfo`).then(response => {
          console.log(response.data.IsSuccess)
          if (response.data.IsSuccess === true) {
            if (this.inRoles('ROLE_other')) {
              // var token = 'token'
              // let params = {data: token, user: localStorage.getItem('user')}
              // this.$store.commit(types.LOGIN, params)
              this.$router.push({name: 'unithome'})
            } else {
              this.$router.push({name: 'Home'})
            }
            // localStorage.setItem('pwdFlag', !!response.data.Passwdrule)
            // if (response.data.Passwdrule) {
            //   this.$router.push({name: 'Home'})
            // } else {
            //   this.$router.push({name: 'password'})
            // }
          } else {
            console.log('获取失败:' + response.data.Msg)
            this.$router.push({name: 'login'})
          }
        }).catch(error => {
          console.log(error)
          this.$router.push({name: 'login'})
        })
      } else {
        this.$router.push({name: 'login'})
      }
    }
  },
  mounted () {
    this.checkLogin()
  }
}
</script>
<style scoped>
#init{
  background: #fff;
  height: 100%;
  text-align: center;
  line-height: 100px;
}
</style>
